package com.gitee.cui.springcloud.service.impl;

import javax.annotation.Resource;

import cn.hutool.core.util.IdUtil;
import com.gitee.cui.springcloud.service.IMessageProvider;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

/**
 * 消息源绑定器通道，用于发送消息到通道
 *
 * @author cuiqingqiang
 * @version 1.0
 * @date 2022-03-16 21:43
 **/
@EnableBinding(Source.class)
public class MessageProviderImpl implements IMessageProvider {

	/**
	 * 消息发送通道
	 */
	@Resource
	private MessageChannel output;

	@Override
	public String send() {
		String serial = IdUtil.simpleUUID();
		output.send(MessageBuilder.withPayload(serial).build());
		System.out.println("************serial: " + serial);
		return null;
	}
}
